<?php
class CategoriaController extends Controller {

    public $layout = '//layouts/amsterdam';

    public function filters() {
        return array(
            'accessControl', // perform access control for CRUD operations
            'postOnly + delete', // we only allow deletion via POST request
        );
    }

    public function init() {
        Yii::app()->clientScript->scriptMap = array('jquery.js' => false, 'jquery.yii.js' => false, 'jquery.yiiactiveform.js' => false);
    }

    /**
     * Specifies the access control rules.
     * This method is used by the 'accessControl' filter.
     * @return array access control rules
     */
    public function accessRules() {
        return array(
            array('allow',  // allow all users to perform 'index' and 'view' actions
                'actions'=>array('index','view'),
                'users'=>array('*'),
            ),
            array('allow', // allow authenticated user to perform 'create' and 'update' actions
                'actions'=>array('crear','update'),
                'users'=>array('@'),
            ),
            array('allow', // allow admin user to perform 'admin' and 'delete' actions
                'actions'=>array('admin','delete'),
                'users'=>array('admin'),
            ),
            array('deny',  // deny all users
                'users'=>array('*'),
            ),
        );
    }

    public function actionIndex() {
        $url = "http://localhost:90/giigo-core/categoria/listarCategorias";

        $categorias = CUrlHandle::callUrl($url);

        $this->render('index', array(
            'categorias' => $categorias
        ));
    }

    public function actionCrear() {
        $model = new Categoria();

        if(isset($_POST['Categoria'])) {
            $model->attributes = $_POST['Categoria'];

            if($model->validate()) {

            }
        }

        $this->render('crear', array(
            'model' => $model
        ));
    }



}